package stream.modifyInnerObject;

import generalobjects.Crowd;
import generalobjects.People;
import generalobjects.PeopleList;
import java.util.ArrayList;
import java.util.List;
import org.testng.annotations.Test;

/**
 * @author
 */
public class RemoveObjectWhenReverse {

    @Test
    private void t1() {
        Crowd crowd = new Crowd();

        PeopleList peopleList = new PeopleList();

        People p1 = new People("a", 1);
        People p2 = new People("b", 2);
        People p3 = new People("c", 3);

        var list = new ArrayList<People>();
        list.add(p1);
        list.add(p2);
        list.add(p3);

        peopleList.setList(list);



        crowd.getPeopleList().add(peopleList);

        crowd.getPeopleList().stream()
            .map(PeopleList::getList)
            .map(list1 -> {
                for (var p : list1) {
                    if (p.getAge() == 2) {
                        list1.remove(p);
                    }
                }

                return list1;
            })
            .forEach(System.out::println);


    }

}
